package com.jianguozh.difs.support.service.constant.enums;

import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.jianguozh.difs.framework.annotation.EnumDesc;
import com.jianguozh.difs.support.service.component.file.core.client.FileClient;
import com.jianguozh.difs.support.service.component.file.core.client.FileClientSetting;
import com.jianguozh.difs.support.service.component.file.core.client.db.DBFileClient;
import com.jianguozh.difs.support.service.component.file.core.client.db.DBFileClientSetting;
import com.jianguozh.difs.support.service.component.file.core.client.ftp.FtpFileClient;
import com.jianguozh.difs.support.service.component.file.core.client.ftp.FtpFileClientSetting;
import com.jianguozh.difs.support.service.component.file.core.client.local.LocalFileClient;
import com.jianguozh.difs.support.service.component.file.core.client.local.LocalFileClientSetting;
import com.jianguozh.difs.support.service.component.file.core.client.s3.S3FileClient;
import com.jianguozh.difs.support.service.component.file.core.client.s3.S3FileClientSetting;
import com.jianguozh.difs.support.service.component.file.core.client.sftp.SftpFileClient;
import com.jianguozh.difs.support.service.component.file.core.client.sftp.SftpFileClientSetting;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 文件存储器枚举
 */
@AllArgsConstructor
@Getter
@EnumDesc(title = "文件存储器类型")
public enum FileStorageEnum implements IEnum<String> {

    DB("DB", "数据库存储器", DBFileClientSetting.class, DBFileClient.class),
    LOCAL("LOCAL", "本地文件存储器", LocalFileClientSetting.class, LocalFileClient.class),
    FTP("FTP", "Ftp文件存储器", FtpFileClientSetting.class, FtpFileClient.class),
    SFTP("SFTP", "Sftp文件存储器", SftpFileClientSetting.class, SftpFileClient.class),
    S3("S3", "S3文件存储器", S3FileClientSetting.class, S3FileClient.class),
    ;

    /**
     * 存储器
     */
    @JsonValue
    private final String value;

    /**
     * 存储器名称
     */
    private final String displayName;

    /**
     * 配置类
     */
    private final Class<? extends FileClientSetting> configClass;

    /**
     * 客户端类
     */
    private final Class<? extends FileClient> clientClass;

    @JsonCreator
    public static FileStorageEnum fromValue(String value) {
        return ArrayUtil.firstMatch(o -> o.getValue().equals(value), values());
    }

}
